package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.BindEquipmentStatusEntity;
import com.egg.ylt.pojo.CaloriesEntity;
import com.egg.ylt.pojo.RealtimeDataEntity;
import com.egg.ylt.presenter.IHealthDataPresenter;
import com.egg.ylt.view.IHealthDataView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.util.HashMap;

public class HealthPresenterImpl extends BasePresenter<IHealthDataView> implements IHealthDataPresenter {
    @Override
    public void getRealtimeData(String companyId, String shopId) {
//        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("companyId", companyId);
        hashMap.put("shopId", shopId);
        RequestManager.getInstance().requestPostByAsyn(API.POST_REALTIME_DATA, hashMap, new ReqCallBack<RealtimeDataEntity>() {

            @Override
            public void onReqSuccess(RealtimeDataEntity result) {
                mView.dismissDialogLoading();
                mView.getData(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void getBabyCalories(String token, String babyId, String code) {
//        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("babyId", babyId);
        hashMap.put("code", code);
        RequestManager.getInstance().requestPostByAsyn(API.POST_CALORIES, hashMap, new ReqCallBack<CaloriesEntity>() {

            @Override
            public void onReqSuccess(CaloriesEntity result) {
                mView.dismissDialogLoading();
                mView.getBabyData(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void getBabyStatus(String token, String babyId, String code) {
//        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("babyId", babyId);
        hashMap.put("code", code);
        RequestManager.getInstance().requestPostByAsyn(API.POST_EQUIPMENT_STATUS, hashMap, new ReqCallBack<BindEquipmentStatusEntity>() {

            @Override
            public void onReqSuccess(BindEquipmentStatusEntity result) {
                mView.dismissDialogLoading();
                mView.getStatus(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
